package lunchy.mvc.controllers;

import java.util.ArrayList;

import lunchy.data.classes.CLunchyMenuGroup;
import lunchy.data.interfaces.ILunchyMenu;
import lunchy.data.interfaces.ILunchyMenuGroup;
import lunchy.mvc.models.CLunchyMenuEditModel;
import lunchy.mvc.views.CLunchyMenuEditGroupView;

public class CLunchyMenuEditController
{
	private CLunchyMenuEditModel model;
	
	public CLunchyMenuEditController()
	{	
		model = new CLunchyMenuEditModel();
	}

	public ArrayList<ILunchyMenuGroup> getMenuGroups()
	{
		return model.getMenuGroups();
	}
	
	public boolean isActiveItem(String id)
	{
		Integer iId = 0;

		try
		{
			iId = Integer.parseInt(id);
		}
		catch(NumberFormatException ex)
		{
			return false;
		}

		return model.isActiveItem(iId);
	}
	
	public void activateItem(String id)
	{
		if(!isActiveItem(id))
		{
			Integer iId = 0;

			try
			{
				iId = Integer.parseInt(id);
				model.activateItem(iId);
			}
			catch(NumberFormatException ex)
			{
				
			}
		}
	}
	
	public void deactivateItem(String id)
	{
		if(isActiveItem(id))
		{
			Integer iId = 0;

			try
			{
				iId = Integer.parseInt(id);
				model.deactivateItem(iId);
			}
			catch(NumberFormatException ex)
			{
				
			}
		}
	}
	
	public boolean saveMenu()
	{
		return model.saveMenu();
	}
	
	public void addGroup()
	{
		model.addGroup();
	}

	public void editGroup(String groupId)
	{
		Integer gId = 0;

		try
		{
			gId = Integer.parseInt(groupId);
			model.editGroup(gId);
		}
		catch(NumberFormatException ex)
		{

		}
	}

	public void editItem(String itemId)
	{
		Integer iId = 0;

		try
		{
			iId = Integer.parseInt(itemId);
			model.editItem(iId);
		}
		catch(NumberFormatException ex)
		{
			ex.printStackTrace();
		}
	}

	public void addItem(String groupId)
	{
		Integer gId = 0;

		try
		{
			gId = Integer.parseInt(groupId);
			model.addItem(gId);
		}
		catch(NumberFormatException ex)
		{

		}
	}

	public void deleteGroup(String groupId)
	{
		Integer gId = 0;

		try
		{
			gId = Integer.parseInt(groupId);
			model.deleteGroup(gId);
		}
		catch(NumberFormatException ex)
		{

		}
	}
	public void deleteItem(String itemId)
	{
		Integer iId = 0;

		try
		{
			iId = Integer.parseInt(itemId);
			model.deleteItem(iId);
		}
		catch(NumberFormatException ex)
		{

		}
	}
}
